#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <unistd.h>
#include <errno.h>
#include <string.h>

int main(int argc, char const *argv[])
{
    int fd, n;
    char msg[] = "here you are";
    char ch[30];
    fd = open("../resource/test.txt", O_RDWR | O_CREAT, 0644);
    if (fd < 0)
    {
        perror("open lseek.txt error");
        exit(1);
    }
    write(fd, msg, strlen(msg));
    lseek(fd, 0, SEEK_SET);
    while ((n = read(fd, ch, 30)) != 0)
    {
        if (n < 0)
        {
            perror("read lseek.txt error");
            exit(1);
        }
        write(STDOUT_FILENO, ch, n);
    }
    close(fd);
    return 0;
}
